package chapter13;

import chapter11.Role;
import chapter12.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-04-17 上午11:28
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
    public boolean addUser(Role role) {
        boolean result = false;
        try {
            Thread.sleep(500);
            result = roleMapper.insertRole(role) > 0;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
    public Role getRole(long id) {
        return roleMapper.getRole(id);
    }
}
